<?php

namespace Cktadmin\Controller;

use Common\Controller\BasicAdmin;
use Common\Service\DataService;

class TasklistController extends BasicAdmin {

    public $table = 'task';

    public function index() {
        $this->title = '套餐管理';
        $where = array();
        $get = I('get.');
        (isset($get['key']) && $get['key'] !== '') && $where['user_name|order_no|alipay_account'] = array('like', "%{$get['key']}%");
        $count = M($this->table)->where($where)->count();
        $db = M($this->table)->where($where)->order('add_time desc');
        return parent::_list($db, $count);
    }

    public function edit() {
        if (IS_POST) {
            $id = I('post.id', '', '0');
            $progress = I('post.progress', 0, 'trim');
            $data = array(
                'progress' => $progress,
                'status' => 0
            );
            if ($progress == 100) {
                $data['status'] = 1;
            }
            if (M($this->table)->where(array('id' => $id))->save($data) !== false) {
                $this->success('设置成功！');
            } else {
                $this->error('设置失败！');
            }
        } else {
            $id = I('get.id', 0, 'intval');
            $info = M($this->table)->find($id);
            $this->assign('vo', $info);
            $this->display();
        }
    }

    public function del() {
        if (DataService::update($this->table)) {
            $this->success('删除成功！');
        }
        $this->error('删除失败！');
    }

}
